/**
  * @Author: songgh
  * @Date: 2021-09-20 14:41:08
  * @LastEditors: songgh
  * @LastEditTime: 2021-09-20 15:41:08
  * @Description: $http
  */
import { HttpRequest } from '@src/utils';
import appConfig from '../../public/static/app-config.json';

export type { ILoginData, IPlannerParams, IUploadData , IServiceSearchParmas, ITokenLoginParams } from './api';
export {
    plannerSearch,
    upload,
    rsaLogin,
    getPublickey,
    serviceSearch,
    getRegionData,
    loginByToken
} from './public';

const { BASE_API: { host, port, base } } = appConfig;
const baseURL = `${host}:${port}/${base}`;
const $http = new HttpRequest();

export async function GET(url, params = {}) {
    let res;
    try {
        res = await $http.get(`${baseURL}${url}`, { params });
    } catch (err: any) {
        throw new Error(err);
    }
    return res?.data;
}

export async function POST(url, data) {
    let res;
    try {
        res = await $http.post(`${baseURL}${url}`, data);
    } catch (err: any) {
        throw new Error(err);
    }
    return res?.data;
}